package cn.dcw.pethome.basic.service.impl;

import cn.dcw.pethome.basic.mapper.BaseMapper;
import cn.dcw.pethome.basic.query.BaseQuery;
import cn.dcw.pethome.basic.service.IBaseService;
import cn.dcw.pethome.basic.util.PageList;
import cn.dcw.pethome.org.domain.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)//添加事务
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> mapper;

    //添加
    @Transactional
    @Override
    public void add(T t) {
        mapper.add(t);
    }
    //删除
    @Override
    @Transactional
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    @Transactional
    public void update(T t) {

    }

    //查询所有
    @Override
    @Transactional
    public List<T> findAll() {
        return mapper.findAll();
    }

    /**
     * 分页查询
     * @param query
     * @return
     */
    @Override
    public PageList<T> pageData(BaseQuery query) {
        //获取总条数
        Long totals = mapper.totals(query);
        //查询部门的集合
        List<T> list = mapper.pageQuery(query);

        return new PageList<>(totals,list);//将查询的结果，封装到对象中
    }

    //批量删除
    @Override
    @Transactional
    public void batchDel(Long[] ids) {
        mapper.batchDel(ids);
    }
}
